﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;

namespace $rootnamespace$
{
    /// <summary>
    /// DemoAPI
    /// </summary>
	[WebApiResult]
    public class DemoAPIController : ApiController
    {
        /// <summary>
        /// 获取数据
        /// </summary>
        /// <returns>数据</returns>
        public string GetData()
        {
            return "Lails.Server";
        }
        /// <summary>
        /// 获取对象
        /// </summary>
        /// <param name="id">对象ID</param>
        /// <returns>DemoModel对象</returns>
        public DemoModel GetModel(long id)
        {
            return new DemoModel() { ID = id, Value = "Value" };
        }
		/// <summary>
        /// 获取对象返回异常结果
        /// </summary>
        /// <param name="id">对象ID</param>
        /// <returns>DemoModel对象</returns>
        public DemoModel GetModelOnException(long id)
        {
            throw new CustomException(-1, "无此ID对象", null);
        }
    }

    /// <summary>
    /// DemoModel对象
    /// </summary>
    public class DemoModel
    {
        /// <summary>
        /// 对象ID
        /// </summary>
        public long ID { get; set; }
        /// <summary>
        /// 对象值
        /// </summary>
        public string Value { get; set; }
    }

	/// <summary>
    /// 自定义异常
    /// </summary>
    public class CustomException : Exception
    {
        public CustomException(int code, string message, Exception ex)
        : base(message, ex)
    {
            this.HResult = code;
        }
    }
}
